home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / misc / zxam16b.lha / ZXAM Spectrum / zxam_rexx / English / Monitor.zxam < prev    next >
Encoding:
Text File  |  1995-01-22  |  6.3 KB  |  263 lines

  1. /* This script is a mini-monitor created by Leonardo Cocaña Galán */
  2. /* Created from some example scripts of ZXAM, and some ownmade work, */
  3. /* of course! */
  4. /* Will be greatly enhanced.... */
  5.  
  6.     /* check if the emulator is there */
  7.     address command
  8.     
  9.     if ~show(ports,ZXAM_REXX) then do
  10.         requestchoice 'title "ZXAM Script error..." body "I couldn't find the emulator's port!!" gadgets "AARGH!"'
  11.         exit
  12.         end
  13.  
  14.     /* open the output window */
  15.     if ~open('fichero','con:0/11/640/256/Example of a simple monitor','W') then exit
  16.     
  17.     dir=zxamgetreg(pc)
  18.     call desambla(dir,16)
  19.     call registros()
  20.  
  21. bucle:    /* more? */
  22.     call print ('Disas(S)emble,(N)ewAdd,Set(PC),(P)oke,P(E)ek,(R)un,')
  23.     dummy=writech('fichero','0a'x)
  24.     call print ('(T)race,Brea(K)Point,Re(L)oad,(B)asic,(Q)uit,(F)ind: ')
  25.     respuesta=input()
  26.     respuesta=upper(respuesta)    
  27.     if (respuesta='S'|respuesta='') then do 
  28.     call desambla(dir,16)
  29.     call registros ()
  30.     end
  31.     if respuesta='Q' then signal cleanup
  32.     if respuesta='N' then call newdir()
  33.     if respuesta='P' then call poke()
  34.     if respuesta='R' then do 
  35.         zxamrun()
  36.         dir=zxamgetreg(pc)
  37.         call desambla(dir,16)
  38.         call registros()
  39.     end
  40.     if respuesta='L' then do 
  41.         call reload
  42.         dir=zxamgetreg(pc)
  43.         call desambla(dir,16)
  44.         call registros()
  45.         end
  46.     if respuesta='B' then do 
  47.         call listbasic
  48.         signal bucle
  49.         end
  50.     if respuesta='PC' then     call setpc
  51.         if respuesta='F'  then  call Findblock
  52.     if respuesta='E'  then  call peek
  53.     if respuesta='T' then do 
  54.         dummy=zxamtrace()
  55.         dir=zxamgetreg(pc)
  56.         call desambla(dir,16)
  57.         call registros()
  58.         end
  59.     if respuesta='K' then call breakpoint
  60. signal bucle
  61.  
  62. Desambla:
  63.  
  64. Parse arg direccion,linias
  65. do i=1 to linias 
  66.         linea=zxamdisassemble(direccion,'d')
  67.         dummy=writech('fichero',substr(linea,2))
  68.         dummy=writech('fichero','0a'x)
  69.         direccion=(direccion+left(linea,1))
  70.         if direccion>65535 then direccion=direccion-65536    
  71. dir = direccion
  72. end i
  73.  
  74. return
  75. registros:
  76. dummy=writech('fichero','0a'x)
  77. dummy=writech('fichero','BC  'zxamgetreg(bc,h))
  78. dummy=writech('fichero','     DE  'zxamgetreg(de,h))
  79. dummy=writech('fichero','     HL  'zxamgetreg(hl,h))
  80. dummy=writech('fichero',"     BC' "zxamgetreg(bc2,h))
  81. dummy=writech('fichero',"     DE' "zxamgetreg(de2,h))
  82. dummy=writech('fichero',"     HL' "zxamgetreg(hl2,h))
  83. dummy=writech('fichero','0a'x)
  84.         
  85. dummy=writech('fichero','IX  'zxamgetreg(ix,h))
  86. dummy=writech('fichero','     IY  'zxamgetreg(iy,h))
  87. dummy=writech('fichero','     SP  'zxamgetreg(sp,h))
  88. dummy=writech('fichero','     PC  'zxamgetreg(pc,h))
  89. dummy=writech('fichero','      I  'zxamgetreg('i',h))
  90. dummy=writech('fichero','        R  'zxamgetreg(r,h))
  91. dummy=writech('fichero','0a'x)
  92. dummy=writech('fichero'," A  "zxamgetreg(a,h))
  93. dummy=writech('fichero',"        F  "zxamgetreg(f,h))
  94. dummy=writech('fichero',"        A' "zxamgetreg(a2,h))
  95. dummy=writech('fichero',"        F' "zxamgetreg(f2,h))
  96.  
  97. dummy=writech('fichero','       IM'zxamgetreg(im))
  98. dummy=writech('fichero','          INT 'zxamgetreg(int))
  99.  
  100. dummy=writech('fichero','0a'x)
  101. dummy=writech('fichero','0a'x)
  102.         
  103. dummy=writech('fichero','S   Z   -   H   -  P/V  N   C')
  104. dummy=writech('fichero','0a'x)
  105.         
  106. dummy=writech('fichero',bittst(d2c(zxamgetreg(f)),7))
  107. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),6))
  108. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),5))
  109. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),4))
  110. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),3))
  111. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),2))
  112. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),1))
  113. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),0))
  114. dummy=writech('fichero','0a'x)
  115. dummy=writech('fichero','0a'x)
  116. return
  117. cleanup:
  118.  
  119.     dummy=close('fichero')
  120.  
  121.     exit
  122. newdir:
  123. call print ('New PC: ')
  124. dir=input()
  125. if (dir>65535 | dir<0)  then signal newdir
  126. call desambla(dir,16)
  127. call registros()
  128. return
  129.  
  130. peek:
  131. call print ('PEEK: ')
  132. pek=input()
  133. if (dir>65535 | dir<0)  then signal peek
  134. call print (zxampeek(pek))
  135. dummy=writech('fichero','0a'x)
  136. return
  137. poke:
  138. call print ('POKE ')
  139. pok=input()
  140. if length(pok)<7 then signal error_long
  141. dirpoke=left(pok,(lastpos(",",pok)-1))
  142. valor=right(pok,(length(pok)-lastpos(',',pok)))
  143. if (dirpoke<16384 | dirpoke>65535) then signal error_dir
  144. if (valor<0 |valor>255) then signal error_val
  145. zxampoke(dirpoke,valor)
  146. return
  147.  
  148. Print:
  149. parse arg texto
  150. dummy=writech('fichero',texto)
  151. return
  152.  
  153. Input:
  154. return readln('fichero')
  155.  
  156. Reload:
  157. zxamparseloaded(zxampploadfile(zxamjoinpathname(zxamactloadpath(),zxamactname())))
  158. return
  159.  
  160. Listbasic:
  161. /* this script extracts the BASIC listing in the spectrum's memory... */
  162.     
  163.     /* start address BASIC (variable PROG) */
  164.     baselist=zxamdpeek(23635)
  165.     
  166.     /* length BASIC (with variable VARS) */
  167.     endlist=zxamdpeek(23627)
  168.     
  169.     /* calculate size */
  170.     longbasic=endlist-baselist
  171.     if longbasic=0 then do
  172.         requestchoice '>nil: title "ZXAM Script error..." body "No BASIC program!!" gadgets "AARGH!"'
  173.         return
  174.         end
  175.     
  176.     /* get the whole BASIC area */
  177.     bloquebasic=zxamgetmem(baselist,endlist-baselist)
  178.  
  179.  
  180.     do forever    
  181.     /* process a line */
  182.         
  183.         numlinea=c2d(left(bloquebasic,2))
  184.         dummy=writech('fichero','  'numlinea)
  185.         longline=c2d(reverse(substr(bloquebasic,3,2)))
  186.         do i=5 to 4+longline    
  187.         if substr(bloquebasic,i,1)='0e'x then do
  188.             i=i+5
  189.             iterate
  190.             end
  191.         dummy=writech('fichero',zxambasictoken(substr(bloquebasic,i,1)))
  192.         
  193.         
  194.         end i
  195.         
  196.     dummy=writech('fichero','0a'x)
  197.     
  198.     bloquebasic=right(bloquebasic,length(bloquebasic)-(longline+4))
  199.     if bloquebasic='' then break
  200.     end
  201. return
  202.  
  203. Setpc:
  204.  
  205. call print ('PC :')
  206. pcdir=input()
  207. if (pcdir>65535 | pcdir<0) then signal setpc
  208. zxamsetreg(pc,pcdir)
  209. dir=zxamgetreg(pc)
  210. call desambla(dir,16)
  211. call registros()
  212. return
  213.  
  214. Error_dir:
  215.  
  216. Call Print ('ERROR: ADDRESS OUT OF RANGE (16384-65535)')
  217. dummy=writech('fichero','0a'x)
  218. Signal poke
  219.  
  220. Error_val:
  221.  
  222. Call print ('ERROR: VALUE OUT OF RANGE (0-255)')
  223. dummy=writech('fichero','0a'x)
  224. Signal poke
  225.  
  226. Error_long:
  227.  
  228. Call print ('ERROR: WRONG PARAMETERS (POKE 60000,255)')
  229. dummy=Writech('fichero','0a'x)
  230. signal poke
  231.  
  232. error_noblock:
  233.  
  234. call print ('DATA BLOCK NOT FOUND')
  235. dummy=writech('fichero','0a'x)
  236. return
  237.  
  238. Findblock:
  239. direc=23296
  240. call print ('Enter data to search (hex):') 
  241. block=x2c(input())
  242. bucle1:
  243. call busca(direc)
  244. if direc<=-1 then do
  245. call error_noblock
  246. return
  247. end
  248. call desambla(direc,3)
  249. direc=dir
  250. signal bucle1
  251. return
  252. busca:
  253. parse arg comienzo
  254. direc=zxamfindblock(comienzo,block)
  255. return
  256.  
  257. breakpoint:
  258. call print('Break Point address: ')
  259. break=input()
  260. if (break<0 |break>65535) then signal breakpoint
  261. zxambreakpoint(break)
  262. return
  263.